package com.windgo.controller.wx;

import com.windgo.bean.bo.WxFeedBackBo;
import com.windgo.bean.MarketUser;
import com.windgo.bean.common.BaseRespVo;
import com.windgo.bean.common.CommonData;
import com.windgo.bean.wxVo.TopicEntity;
import com.windgo.bean.wxVo.WxTopicDetailVo;
import com.windgo.bean.wxVo.WxTopicListVo;
import com.windgo.service.CategoryService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 张林浩
 * @since 2022/10/14 19:42
 */

@RestController
@RequestMapping("wx")
public class WxTopicController {

    @Autowired
    CategoryService categoryService;

    @GetMapping("topic/list")
    public BaseRespVo list(Integer page, Integer limit) {
        CommonData<WxTopicListVo> wxTopicListVoCommonData = categoryService.getTopicList(page, limit);
        return BaseRespVo.ok(wxTopicListVoCommonData);
    }

    @GetMapping("topic/detail")
    public BaseRespVo detail(Integer id) {
        WxTopicDetailVo wxTopicDetailVo = categoryService.getTopicDetailById(id);
        return BaseRespVo.ok(wxTopicDetailVo);
    }

    @GetMapping("topic/related")
    public BaseRespVo related(Integer id) {
        CommonData<TopicEntity> commonData = categoryService.getTopicRelated(id);
        return BaseRespVo.ok(commonData);
    }

    @PostMapping("feedback/submit")
    public BaseRespVo feedback(@RequestBody WxFeedBackBo wxFeedBackBo) {
        Subject subject = SecurityUtils.getSubject();
        MarketUser marketUser = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        int code = categoryService.addFeedBack(wxFeedBackBo, marketUser);
        if (code == 200) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.ok(0, "提交反馈失败");

    }

}
